home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 101 / CD-ROM 101.iso / compl / maya5ple / Install_MayaPLE5_English.exe / Maya / Data1.cab / MLdeleteUnused.mel < prev    next >
Encoding:
Text File  |  2003-07-17  |  6.2 KB  |  190 lines

  1. // Copyright (C) 1997-2002 Alias|Wavefront,
  2. // a division of Silicon Graphics Limited.
  3. //
  4. // The information in this file is provided for the exclusive use of the
  5. // licensees of Alias|Wavefront.  Such users have the right to use, modify,
  6. // and incorporate this code into other products for purposes authorized
  7. // by the Alias|Wavefront license agreement, without fee.
  8. //
  9. // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
  10. // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
  11. // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
  12. // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
  13. // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
  14. // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  15. // PERFORMANCE OF THIS SOFTWARE.
  16. //
  17. ////////////////////////////////////////////////////////////////////////////////
  18. //
  19. //  Procedure Name:
  20. //      MLdeleteUnused
  21. //
  22. //  Description:
  23. //         Delete unused multi-lister (render) nodes
  24. //        
  25. //  Input Arguments:
  26. //      None.
  27. //
  28. //  Return Value:
  29. //      None.
  30. //
  31. global proc MLdeleteUnused() {
  32.     int $i, $j, $count;
  33.  
  34.     // Delete all empty shadinggroups or not connected shadinggroups first.
  35.     string $sets[] = `ls -sets`;
  36.     string $objs[];
  37.     $count = `size($sets)`;
  38.     for ($i = 0; $i < $count; $i++) {
  39.         if (`sets -q -renderable $sets[$i]`) {
  40.             if ($sets[$i] != "initialShadingGroup" &&
  41.                 $sets[$i] != "initialParticleSE") {
  42.                 $objs = `sets -q $sets[$i]`;
  43.                 if (size($objs) == 0) {
  44.                     deleteIfNotReferenced $sets[$i];
  45.                 } else {
  46.                     string $connSurf[] = 
  47.                         `listConnections ($sets[$i] + ".surfaceShader")`;
  48.                     string $connVol[] =
  49.                         `listConnections ($sets[$i] + ".volumeShader")`;
  50.                     string $connDisp[] =
  51.                         `listConnections ($sets[$i] + ".displacementShader")`;
  52.                     if (`size $connSurf` == 0 && `size $connVol` == 0 &&    
  53.                         `size $connDisp` == 0) {
  54.                         deleteIfNotReferenced $sets[$i];
  55.                     }
  56.                 }
  57.             }
  58.         }
  59.         clear $objs;
  60.     }
  61.  
  62.     // Delete all unconnected materials.
  63.     int $shouldDelete = false;
  64.     int $count2;
  65.     string $materials[] = `ls -long -mat`;
  66.     string $se[];
  67.     string $conn[];
  68.     $count = `size($materials)`;
  69.     for ($i = 0; $i < $count; $i++) {
  70.         // Now determine if the readOnly connections are done.
  71.         string $currShader = $materials[$i];
  72.  
  73.         $conn = `listConnections -shapes true -connections true -source false $currShader`;
  74.         // conn is an array of plug/connection pairs 
  75.         $count2 = `size($conn)`;
  76.         for ($j = 0; $j < $count2; $j+=2) {
  77.             clear $se;
  78.             if ($conn[$j] != ($currShader + ".message")) {
  79.                 $shouldDelete = false;
  80.                 break;
  81.             } else {
  82.                 // must explicitly check for a shading engine connection on message
  83.                 $se = `listConnections -type shadingEngine ($conn[$j])`;
  84.                 if (size($se) != 0) {                
  85.                     $shouldDelete = false;
  86.                     break;
  87.                 } else {
  88.                     $shouldDelete = true;
  89.                 }
  90.             }
  91.         }
  92.  
  93.         if ($shouldDelete) {
  94.             deleteIfNotReferenced $currShader;
  95.         }
  96.             
  97.         $shouldDelete = false;
  98.         clear $conn;
  99.         clear $se;
  100.     }
  101.  
  102.     // Iterate multi-times and delete textures + utility nodes.
  103.     int $deleteAnything = true;
  104.     int $oldSizeAll = 0;
  105.     string $all[];
  106.     string $class[];
  107.     string $conn[];
  108.     string $base[];
  109.     string $type,$node,$connType,$attrName;
  110.     while ($deleteAnything) {
  111.         $deleteAnything = false;
  112.         $all = `ls -long -dep`; 
  113.         $count = size($all);
  114.         if($oldSizeAll != $count) {
  115.             for ($node in $all) {
  116.                 // Deleting one node can delete other connected nodes.
  117.                 if (!`objExists $node`)
  118.                     continue;
  119.  
  120.                 $type = `nodeType $node`;
  121.                 $class = `getClassification $type`;
  122.  
  123.                 if (size($class) == 0)
  124.                     continue;
  125.  
  126.                 // A heightField might not have any output connections, so
  127.                 // look for an input connection before treating it as
  128.                 // just a regular utility node...
  129.                 //
  130.                 if( $type == "heightField" ) {
  131.                     $conn = `listConnections -connections true 
  132.                         -source true -shapes true $node`;
  133.                     if( size( $conn ) != 0 ) {
  134.                         continue;
  135.                     }
  136.                 }
  137.  
  138.                 tokenize ($class[0], "/", $base);
  139.                 if ($base[0] == "texture" || 
  140.                     $base[0] == "utility" ||
  141.                     $base[0] == "imageplane" ||
  142.                     $base[0] == "shader")
  143.                 {
  144.                     // It's a texture, postprocess or utility node.
  145.                     // Now determine if the readable connections are done.
  146.                     $shouldDelete = true;
  147.  
  148.                     $conn = `listConnections -connections true -source false -shapes true $node`;
  149.                     int $connCount = size($conn);
  150.                     for ($j = 0; $j < $connCount; $j+=2) {
  151.                         $attrName = match (".message",$conn[$j]);
  152.                         if ($attrName == ".message") {
  153.                             // must explicitly check for the following
  154.                             // destinations on a message attribute:
  155.                             // shading engine, arrayMapper, or a
  156.                             // camera in the case of imagePlane or
  157.                             // cameraView
  158.                             $connType = `nodeType $conn[$j+1]`;
  159.                             if ($connType  == "shadingEngine"
  160.                                 || $connType == "camera"
  161.                                 || $connType == "imagePlane"
  162.                                 || $connType == "arrayMapper")
  163.                             {
  164.                                 $shouldDelete = false;
  165.                                 break;
  166.                             }
  167.                         }
  168.                         else {
  169.                             $shouldDelete = false;
  170.                             break;
  171.                         }
  172.                     } // foreach destination connection
  173.                     if ($shouldDelete) {
  174.                         deleteIfNotReferenced $node;
  175.                         $deleteAnything = true;
  176.                     }
  177.                 } // node is texture, utility, or shader
  178.  
  179.                 $shouldDelete = false;
  180.             } // foreach dependency node
  181.             $oldSizeAll = $count;
  182.         }
  183.         else {
  184.             $deleteAnything = false;
  185.         }
  186.         clear $class;
  187.         clear $base;
  188.     }
  189. }
  190.